package com.buba.controller;


import com.buba.service.SpareUseService;
import common.R;
import entity.sparemanage.SpareUse;
import entity.sparemanage.dto.insertSpareUseDto;
import entity.sparemanage.dto.selAllSpareUseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import utils.PageResult;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 备件领用 前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-05-18
 */
@RestController
@RequestMapping("/spare-use")
public class SpareUseController {

    @Autowired
    private SpareUseService spareUseService;

    /* *
     * @Author: beisheng
     * @Descriprion: 全查模糊查分页查询备件领用单列表
     * @Date: 2023/6/2 9:01
     * @Return: common.R
     * @Param: [selAllSpareUseDto]
     */

    @PostMapping("/selAllSpareUse")
    public R selAllSpareUse(@RequestBody selAllSpareUseDto selAllSpareUseDto){
        PageResult pageResult = spareUseService.selAllSpareUse(selAllSpareUseDto);
        return R.success(pageResult);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 批量逻辑删除领用单
     * @Date: 2023/6/14 16:20
     * @Return: common.R
     * @Param: [ids]
     */

    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<Integer> ids){
        List<SpareUse> list = new ArrayList<>();
        for (Integer id : ids) {
            SpareUse spareUse = new SpareUse();
            spareUse.setSpId(id);
            spareUse.setDeleteFlag(1);
            list.add(spareUse);
        }
        spareUseService.updateBatchById(list);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 新增领用申请
     * @Date: 2023/6/15 8:54
     * @Return: common.R
     * @Param: [spareUseDto]
     */

    @PostMapping("/insertSpareUse")
    public R insertSpareUse(@RequestBody insertSpareUseDto spareUseDto){
        spareUseService.insertSpareUse(spareUseDto);
        return R.success();
    }
}

